package gria

import gria.*
import simpleauth.User

class GriaApplicationController {
    
    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only accept POST requests
    def allowedMethods = [delete:'POST', save:'POST', update:'POST']

    def list = {
        if(!params.max) params.max = 10
        [ griaApplicationList: GriaApplication.list( params ) ]
    }

    def show = {
        def griaApplication = GriaApplication.get( params.id )

        if(!griaApplication) {
            flash.message = "GriaApplication not found with id ${params.id}"
            redirect(action:list)
        }
        else { return [ griaApplication : griaApplication ] }
    }

    def delete = {
        def griaApplication = GriaApplication.get( params.id )
        if(griaApplication) {
            griaApplication.delete()
            flash.message = "GriaApplication ${params.id} deleted"
            redirect(action:list)
        }
        else {
            flash.message = "GriaApplication not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def griaApplication = GriaApplication.get( params.id )

        if(!griaApplication) {
            flash.message = "GriaApplication not found with id ${params.id}"
            redirect(action:list)
        }
        else {
            return [ griaApplication : griaApplication ]
        }
    }

    def update = {
        def griaApplication = GriaApplication.get( params.id )
        if(griaApplication) {
            griaApplication.properties = params
            if(!griaApplication.hasErrors() && griaApplication.save()) {
                flash.message = "GriaApplication ${params.id} updated"
                redirect(action:show,id:griaApplication.id)
            }
            else {
                render(view:'edit',model:[griaApplication:griaApplication])
            }
        }
        else {
            flash.message = "GriaApplication not found with id ${params.id}"
            redirect(action:edit,id:params.id)
        }
    }

    def create = {
        def griaApplication = new GriaApplication()
        griaApplication.properties = params
        return ['griaApplication':griaApplication]
    }

    def save = {
        def griaApplication = new GriaApplication(params)
        if(!griaApplication.hasErrors() && griaApplication.save()) {
            flash.message = "GriaApplication ${griaApplication.id} created"
            redirect(action:show,id:griaApplication.id)
        }
        else {
            render(view:'create',model:[griaApplication:griaApplication])
        }
    }
}
